﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 图书管理系统
{
    public class Dao
    {
        SqlConnection sc;
        public SqlConnection connect()
        {
            string str = @"Data Source=.;Initial Catalog=BookDB;Integrated Security=True";
             sc = new SqlConnection(str);//数据库链接
            sc.Open();//打开数据库
            return sc;
        }

        public SqlCommand command(string sql)
        {
            SqlCommand cmd = new SqlCommand(sql, connect());
            return cmd;
        }
        //更新操作
        public int Execute(string sql)
        {
            return command(sql).ExecuteNonQuery();
        }
        //读取操作
        public SqlDataReader read(string sql)
        {
            return command(sql).ExecuteReader();
        }
        //关闭数据库链接
        public void DaoClose()
        {
            sc.Close();
        }
    }
}
